﻿﻿﻿

<!--********************* Part1:Jsp Head *********************-->

<%@ page contentType="text/html;charset=UTF-8"%>  
<%@ include file="/framework/head.jsp"%>
<%@page import="java.util.Vector"%>
<%@page import="system.base.InOutStatisticSearchClass"%>
<%@page import="java.util.*"%>

<!--********************* Part2:Java Code *********************-->
<%
    InOutStatisticSearchEvent event = (InOutStatisticSearchEvent)context.getSessionValue("InOutStatisticSearchEvent");
    ObjectList list = InOutStatistic.fetch().detailqueryGroupForInit(con,event,context.getString("isFirstVisit"));
    InOutStatisticSearchClass iossc = new InOutStatisticSearchClass();
    ObjectList warehouseList = (ObjectList)context.getSessionValue("WarehouseListDetail");

%>

<!--********************* Part3:JavaScript Code ***************-->
<!--start 客户端脚本区域-->
<%@page import="system.base.InOutStatisticSearchClass.FirstForm"%>
<%@page import="system.base.InOutStatisticSearchClass.FirstForm"%>
<%@page import="framework.core.StringUtil"%>
<%@page import="system.base.InOutStatisticSearchClass.FirstForm"%>

<%@page import="utils.system"%><script language=javascript>

var list_code = "listInOutStatistic";

function doSearch()
{

	if(GetValue("i_StartStatisticTime") == "" && GetValue("i_EndStatisticTime") != ""){
            alert("起始日期不可为空!");
            return false;
    }
    
    var warehouseCodes = $.jstree._reference("#warehouseLevel").get_checked();
    var warehouseList = new Array();
    var i = 0;
     $.each(warehouseCodes, function() {
	           warehouseList[i] =($(this).attr("id"));
	           i++;
		});

    SetValue("WarehouseCodes",warehouseList);
    
    SetValue("s_ProviderName",GetValue("i_ProviderName")); //供应商

    SetValue("s_BalanceFlag",GetValue("i_BalanceFlag")); //结算状态

    SetValue("s_StartStatisticTime",GetValue("i_StartStatisticTime")); //统计开始时间
    
    SetValue("s_EndStatisticTime",GetValue("i_EndStatisticTime")); //统计结束时间

    SetValue("s_IsNormal",GetValue("i_IsNormal")); //是否正式产品

    SetValue("s_BalanceMode",GetValue("i_BalanceMode")); //结算模式
    
    SetValue("s_ProductCode",GetValue("i_ProductCode")); //产品编码
    
    SetValue("s_ProductName",GetValue("i_ProductName")); //产品名称
    
    SetValue("s_ProductBrand",GetValue("i_ProductBrand")); //品牌
 
    doCommonSearch();
}

function doExport()
{                
   /* if(GetValue("i_ProviderName") == ""){
        alert("请输入供应商名称!");
        return false;
    }
    if(GetValue("i_StartStatisticTime") == ""){
        alert("请输入开始时间!");
        return false;
    }
    if(GetValue("i_EndStatisticTime") == ""){
        alert("请输入结束时间!");
        return false;
    }
    */
    SetAction("exportInOutStatistic");
    frm.submit();
}

/*
function bizViewInHead(id)
{
    viewWin("<%=Config.getSrv()%>?action_code=viewInHead&Id="+id);
}

function doDelete()
{
    if(!hasChooseRadio("ids"))
    {
        bizMessage("删除","入库单主表");
        return false;
    }
    if(!bizConfirm("删除","入库单主表")) return false;
    SetAction("deleteInHead");
    frm.submit();
}

function doToAdd()
{
    SetAction("toAddInHead");
    frm.submit();
}

function doToUpdate()
{
    if(!checkOne("ids")) 
    {
        bizMessage("修改","入库单主表");
        return false;
    }
    SetValue("Id",getCheckBoxValue("ids"));
    SetAction("toUpdateInHead");
    frm.submit();
}
function doToCopy()
{
    if(!checkOne("ids")) 
    {
        bizMessage("复制","入库单主表");
        return false;
    }
    SetValue("Id",getCheckBoxValue("ids"));
    SetAction("toCopyInHead");
    frm.submit();
}
*/
key_InitDefault();
key_RegSubmitHandler(doSearch);
</script>
<script type="text/javascript" src = "<%=Config.getWebPath()%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src = "<%=Config.getWebPath()%>/js/jquery.jstree.js"></script>
<link type="text/css" rel="stylesheet" href="<%=Config.getWebPath()%>/css/themes/default/style.css"/>
<script type="text/javascript">
	   $(function() {
		    $("#warehouseLevel").jstree({
		        "plugins" : [ "themes", "html_data", "checkbox", "ui" ]
		       
		    });
		    
		    var checkedWarehouseCodes = "<%=event.getWarehouseCodes()[0]%>";
		    
		    if(checkedWarehouseCodes == "") checkedWarehouseCodes = "00";
		    
		    var arrayCheckedWarehouseCodes = checkedWarehouseCodes.split(",");
		   		  	
		  	var checkSel = function(ary, val) {
		  		for(var i=0; i<ary.length; i++) {
		  			if(ary[i] == val) {
		  				return true;
		  			}
		  		}
		  		
		  		return false;
		  	}
		    <%if(context.getString("isFirstVisit").equals("false")){ %>
			  	$("#warehouseLevel li").each(
			  		function() 	{
			  			if(checkSel(arrayCheckedWarehouseCodes, $(this).attr("id"))) {
			  				$.jstree._reference("#warehouseLevel").check_node($(this));
			  			} 	  			
			  		}
			  	);
		  	<%}
		  	%>
		  
		});
		
		
</script>
<%=uiBody%>>

<%@ include file="/framework/menu.jsp"%>

<!--********************* Part4:Form  ***************-->
<form id=frm action="<%=Config.getSrv()%>" method="post">
<input type=hidden name="action_code" value="">
<input type=hidden name="Id" value="">
<input type=hidden name=sortOrder value="1">

<!--查询条件保留区域-->

<input type=hidden name="WarehouseCodes" value="<%=event.getWarehouseCodes()[0]%>" > 

<input type=hidden name="s_ProviderName" value="<%=event.getProviderName()%>"> <!--供应商-->

<input type=hidden name="s_BalanceFlag" value="<%=event.getBalanceFlag()%>"> <!--结算状态-->

<input type=hidden name="s_StartStatisticTime" value="<%=event.getStartStatisticTime()%>"> <!--统计开始时间-->

<input type=hidden name="s_EndStatisticTime" value="<%=event.getEndStatisticTime()%>"> <!--统计结束时间-->

<input type=hidden name="s_IsNormal" value="<%=event.getIsNormal()%>"> <!--是否正式产品-->

<input type=hidden name="s_BalanceMode" value="<%=event.getBalanceMode()%>"> <!--结算模式-->

<input type=hidden name="s_ProductCode" value="<%=event.getProductCode()%>"> <!--产品编码-->

<input type=hidden name="s_ProductName" value="<%=event.getProductName()%>"> <!--产品名称-->

<input type=hidden name="s_ProductBrand" value="<%=event.getProductBrand()%>"> <!--品牌-->

<%String startTime = "";String endTime = "";%>
<script language="javascript">
    if(GetValue("s_StartStatisticTime") != ""){
        <%startTime = event.getStartStatisticTime();%>
    }
    if(GetValue("s_EndStatisticTime") != ""){
        <%endTime = event.getEndStatisticTime();%>
    }
</script>
<%@ include file="/framework/list_head.jsp"%>

<br>
<!--********************* Part5:Search Area ***************-->
<%=uiSearchStart%>>
<%
    int key_tab = 1 ;
%>


    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
            仓库选择：
            
            <div id="warehouseLevel" style="background-color: DEE4E9">
				<%=Warehouse.getWarehouseTree(warehouseList,event.getWarehouseCodes())%>
			</div>
            
        </td>       
    </tr>
    
    
    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
              供应商：&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProviderName" size="20" value="<%=event.getProviderName()%>" key_tab="<%=key_tab++%>">
            &nbsp;&nbsp;&nbsp;&nbsp;结算状态：
            <%=SelectManager.viewBalanceOrNoSelect("i_BalanceFlag",event.getBalanceFlag(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
            &nbsp;&nbsp;&nbsp;&nbsp;产品编码：&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProductCode" size="20" value="<%=event.getProductCode() %>" key_tab="<%=key_tab++%>">
        </td>       
    </tr>
    
      <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
             产品名称：
            <input type="text" class="texts" name="i_ProductName" size="20" value="<%=event.getProductName()%>" key_tab="<%=key_tab++%>">
   	 &nbsp;&nbsp;&nbsp;&nbsp;品牌：&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="text" class="texts" name="i_ProductBrand" size="20" value="<%=event.getProductBrand()%>" key_tab="<%=key_tab++%>">
     &nbsp;&nbsp;&nbsp;&nbsp;结算模式：&nbsp;&nbsp;
            <%=SelectManager.viewYKorMD("i_BalanceMode",event.getBalanceMode(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
        </td>
    </tr>
    
    <%=uiSearchInputTR%>>
        <%=uiSearchInputTDHead%>>
              统计日期：
            <%=framework.custom.UIManager.generateDateInput("i_StartStatisticTime", startTime)%> 至 <%=framework.custom.UIManager.generateDateInput("i_EndStatisticTime", endTime)%>
            &nbsp;&nbsp;&nbsp;&nbsp;是否正式产品：
            <%=SelectManager.viewYesOrNoSelect("i_IsNormal",event.getIsNormal(),true,"",SelectManager.SELECT_ALL,"","key_tab="+(key_tab++))%>
     &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="查询" class="buttons" onclick="doSearch();return false;">&nbsp;<input type="button" value="清空" class="buttons" onclick="doClearEvent();return false;">
        </td>       
    </tr>
    
  

<%=uiSearchEnd%>

<!--列表标题-->
<%=UIManager.addListHeadTitle("产品期间出入库统计")%>

<!--********************* Part6:List Area ***************-->

<%=uiListStart%>>

<%@ include file="/framework/list_foot.jsp"%>

<%
    int index = 1 ;
%>  
    <%=uiListHeadTR%>>
        <%=UIManager.addListHead("产品编码",index++)%>

        <%=UIManager.addListHead("产品名称",index++)%>

        <%=UIManager.addListHead("单位",index++)%>

        <%=UIManager.addListHead("规格",index++)%>

        <%=UIManager.addListHead("型号",index++)%>

        <%=UIManager.addListHead("品牌",index++)%>

        <%=UIManager.addListHead("供应商",index++)%>
        <%=UIManager.addListHead("单价",index++)%>
        <%=UIManager.addListHead("入库数量",index++)%>
        <%=UIManager.addListHead("入库金额",index++)%>
        <%=UIManager.addListHead("出库数量",index++)%>      
        <%=UIManager.addListHead("出库成本",index++)%>
    <%=uiListHeadTREnd%>>
    
    <!--data-->
<%


//入库金额 line11
double line11 = 0;
//出库成本 line13
double line13 = 0;
//库存成本 line15
double line15 = 0;
//入库单价
double line16 = 0;
//出库单价
double line17 = 0;
  
int size = list.size();

  
if(size > 0){
	//郑斌
	InOutStatisticSearchClass.FirstForm moneyForm = (InOutStatisticSearchClass.FirstForm)list.get(list.size()-1);
	//list.remove(list.size()-1);
	//Vector vec = iossc.setAll(con,list,event);
	String in_money = String.valueOf(moneyForm.inMoney)== null ? "0" : String.valueOf(moneyForm.inMoney);
	String out_money = String.valueOf(moneyForm.outMoney)==null ? "0" : String.valueOf(moneyForm.outMoney);
	String storage_money = String.valueOf(moneyForm.nowMoney)==null ? "0" : String.valueOf(moneyForm.nowMoney);
	size--;
    for(int i=0;i<size;i++)
    {
        String strValue = "";
        UniversalRow row = (UniversalRow)list.get(i);
%>
    <%=uiListDataTR[i%2]%> align=center> 
        <%=uiListDataTD%>><%=row.getString("PRODUCT_CODE")==null ? "" : row.getString("PRODUCT_CODE")%></td>
        <%=uiListDataTD%>><%=row.getString("PRODUCT_NAME")==null ? "" : row.getString("PRODUCT_NAME")%></td>
        <%=uiListDataTD%>><%=row.getString("PRODUCT_UNIT")==null ? "" : row.getString("PRODUCT_UNIT")%></td>
        <%=uiListDataTD%>><%=row.getString("SPEC")==null ? "" : row.getString("SPEC")%></td>
        <%=uiListDataTD%>><%=row.getString("MODEL")==null ? "" : row.getString("MODEL")%></td>
        <%=uiListDataTD%>><%=row.getString("PRODUCT_BRAND")==null ? "" : row.getString("PRODUCT_BRAND")%></td>
        <%=uiListDataTD%>><%=row.getString("PROVIDER_NAME")==null ? "" : row.getString("PROVIDER_NAME")%></td>
         <%
            strValue = row.getString("PRODUCT_PRICE")=="0" ? "0" : row.getString("PRODUCT_PRICE");
            strValue = StringUtil.showPrice4(strValue);
            //
            line16 = line16 + Double.parseDouble(row.getString("PRODUCT_PRICE"));
        %>
        <%=uiListDataTD%>><%=strValue%></td>
  
         	<%  double finalCount = Double.parseDouble(row.getString("FINAL_COUNT")=="0" ? "0" :row.getString("FINAL_COUNT"));
         		double inCount = Double.parseDouble(row.getString("IN_COUNT")=="0" ? "0" : row.getString("IN_COUNT"));
         	 	double outCount = Double.parseDouble(row.getString("OUT_COUNT")=="0" ? "0": row.getString("OUT_COUNT"));
         	 	double showFinalCount = finalCount+outCount-inCount;
         	 %>
 
          	<% 
          		double inMoney =Double.parseDouble(row.getString("IN_MONEY")=="0" ? "0" : row.getString("IN_MONEY"));
          		double outMoney = Double.parseDouble(row.getString("OUT_MONEY")=="0" ? "0" : row.getString("OUT_MONEY"));
          		double finalMoney = Double.parseDouble(row.getString("FINAL_MONEY")=="0" ? "0" : row.getString("FINAL_MONEY"));
          		double showFinalMoney = finalMoney+outMoney - inMoney;
          	%>
      
        <%=uiListDataTD%>><%=StringUtil.showCount(String.valueOf(inCount)) %></td>
 
        <%
            strValue = row.getString("IN_MONEY")=="0" ? "" : row.getString("IN_MONEY");
            strValue = StringUtil.showPrice(strValue);
            line11 = line11 + Double.parseDouble(row.getString("IN_MONEY"));
        %>
        <%=uiListDataTD%>><%=strValue%></td>
        <%=uiListDataTD%>><%=StringUtil.showCount(String.valueOf(outCount))%></td>
        
        <%
            strValue = row.getString("OUT_MONEY")=="0" ? "0" : row.getString("OUT_MONEY");
            strValue = StringUtil.showPrice(strValue);
            //
            line13 = line13 + Double.parseDouble(row.getString("OUT_MONEY"));
        %>
        <%=uiListDataTD%>><%=strValue%></td>

 
    </tr>
<%  
    }
%>
<%=uiListDataTR[0]%> align=center>    
<%=uiListDataTD%> colspan='9' align = right >
            <b><%="本页入库金额合计:<BR>"+framework.core.StringUtil.showPrice(""+line11)%></b>
    </td>
    
    
<%=uiListDataTD%> colspan='3' align = right >
            <b><%="本页出库成本合计:<BR>"+framework.core.StringUtil.showPrice(""+line13)%></b>
    </td>
    
</tr>
<%=uiListDataTR[0]%> align=center>    
<%=uiListDataTD%> colspan='9' align = right >
            <b><%="总计入库金额:<BR>"+framework.core.StringUtil.showPrice(""+in_money)%></b>
    </td> 
<%=uiListDataTD%> colspan='3' align = right >
            <b><%="总计出库成本:<BR>"+framework.core.StringUtil.showPrice(""+out_money)%></b>
    </td> 
    <% }else{ %>
    <%=uiListDataTR[0]%> align=center>    
<%=uiListDataTD%> colspan='18' align = center >
<b><font color="red">没有符合条件的查询结果</font></b>
</tr><%} %>


<%@ include file="/framework/list_foot2.jsp"%>

<%=uiListEnd%>


<!--********************* Part7:Action Area ***************-->
<%=uiCommandStart%>>
    <%=uiCommandTR%>>
        <%=uiCommandTD%>>
        <input type=button value="   导出   " class="buttons" onclick="doExport();return false;">
        </td>
    </tr>   
<%=uiCommandEnd%>
</form>

<%@ include file="/framework/foot.jsp"%>

<!--
    Author    :Wing
    FileName  :/system/base/InHeadList.jsp
-->
